//
//  SignCell.m
//  SouthChina
//
//  Created by creator_lq on 14/12/31.
//  Copyright (c) 2014年 科创. All rights reserved.
//

#import "SignCell.h"

@implementation SignCell

@synthesize message;
@synthesize publicId;




- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        _allcontentView =[[UIImageView alloc]initWithFrame:CGRectZero];
        _backgroundImage =[[UIImageView alloc]initWithFrame:CGRectZero];
        
        
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _timeLabel = [[UILabel alloc]initWithFrame:CGRectZero];

        _signBox = [[UIButton alloc]initWithFrame:CGRectZero];

        [_titleLabel setFont:[UIFont systemFontOfSize:FONT_TITLE_SIZE_SIGN]];
        
        [_signBox.titleLabel setFont:[UIFont systemFontOfSize:14]];
        _timeLabel.textColor = BASIC_GRAYLINE_COLOR;
        [_timeLabel setFont:[UIFont systemFontOfSize:13]];

        [self addSubview:_allcontentView];
        
        [_allcontentView addSubview:_backgroundImage];
        [_backgroundImage addSubview:_titleLabel];
        [_backgroundImage addSubview:_timeLabel];
        [_backgroundImage addSubview:_signBox];
        
        [_backgroundImage bringSubviewToFront:_signBox];

        
        [self setBackgroundColor:[UIColor clearColor]];
        
    }
    return self;
}

- (void)layoutSubviews{
    
    
    CGSize contentSize = [message.text sizeWithFont:[UIFont systemFontOfSize:FONT_TITLE_SIZE_SIGN] constrainedToSize:CGSizeMake(SCREEN_WIDTH-5*NEW_CELL_COM_GAP-SIGN_BTN_WIDTH, CGFLOAT_MAX)lineBreakMode:NSLineBreakByWordWrapping];
    
 
    long totalHeight = TIME_SING_HEIGHT +(6*NEW_CELL_COM_GAP) + contentSize.height;
 
    self.allcontentView.frame =  CGRectMake(0, 0, SCREEN_WIDTH, totalHeight);
    self.backgroundImage.frame =  CGRectMake(NEW_CELL_COM_GAP, NEW_CELL_COM_GAP, SCREEN_WIDTH-2*NEW_CELL_COM_GAP, totalHeight-2*NEW_CELL_COM_GAP);
    [self.backgroundImage setImage:[[UIImage imageNamed:@"news_background_normal"]stretchableImageWithLeftCapWidth:5 topCapHeight:5]];
    
    self.titleLabel.frame = CGRectMake(NEW_CELL_COM_GAP, NEW_CELL_COM_GAP, contentSize.width, contentSize.height);
    self.titleLabel.text = message.text;
    self.titleLabel.numberOfLines = 0;//表示label可以多行显示
    self.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;//换行模式，与上面的计算保持一致。
 
    
    self.signBox.frame = CGRectMake(_backgroundImage.frame.size.width-NEW_CELL_COM_GAP-SIGN_BTN_WIDTH, (_backgroundImage.frame.size.height-SIGN_BTN_HEIGHT)/2,SIGN_BTN_WIDTH, SIGN_BTN_HEIGHT);
    
    if ([@"1" isEqualToString:[message getValue:@"signState"]]) {
        [self.signBox setBackgroundImage:[UIImage imageNamed:@"color_btn_disable"] forState:UIControlStateNormal];
        [self.signBox setTitle:@"已签收" forState:UIControlStateNormal];
        [self.signBox setUserInteractionEnabled:NO];
        
    }else{
        [self.signBox setBackgroundImage:[[UIImage imageNamed:@"blue_btn_normal"] stretchableImageWithLeftCapWidth:20 topCapHeight:20]forState:UIControlStateNormal];
        [self.signBox setTitle:@"签收" forState:UIControlStateNormal];
        [self.signBox setUserInteractionEnabled:NO];

    }


    self.timeLabel.frame = CGRectMake(NEW_CELL_COM_GAP, 2*NEW_CELL_COM_GAP+contentSize.height, 200,TIME_SING_HEIGHT);
    self.timeLabel.textAlignment = NSTextAlignmentLeft;
    self.timeLabel.text=[message.upate_time stringFromDate];
    
 
    
    
}


-(void) setMsgCellValue:(Message*)msg publicId:(NSString*)publicIdd{
    
    self.message = msg;
    self.publicId = publicIdd;
    
}




@end
